package acom.test.swing.bb;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ButtonMenutest {

	static final int WIDTH = 500;
	static final int HEIGHT = 400;

	private int position_x = 20;
	private int position_y = 20;

	private JFrame frame;
	
	private CardLayout cardLayout;

	private JButton menubut;
	private JPanel cardPane;
	private JPanel visiblePane;
	private JPanel hidePane;

	private JLabel add_lb;
	private JLabel set_lb;
	
	private boolean visible =true;

	public ButtonMenutest() {
		frame = new JFrame();
		frame.setTitle("button 制作 menu 效果");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setLayout(null);

		menubut = new JButton("设置");
		cardPane = new JPanel();
		cardLayout = new CardLayout();
		cardPane.setLayout(cardLayout);

		visiblePane = new JPanel();
		hidePane = new JPanel();

		cardPane.add(visiblePane, "p1");
		cardPane.add(hidePane, "p2");

		add_lb = new JLabel("导入名单");
		set_lb = new JLabel("奖项设置");
		visiblePane.setLayout(new GridLayout(2, 2));
		visiblePane.add(add_lb);
		visiblePane.add(set_lb);

		init();

		frame.setSize(WIDTH, HEIGHT);
		frame.add(menubut);
		frame.add(cardPane);
		frame.setVisible(true);
	}

	public void init() {
		menubut.setBounds(position_x, position_y, 80, 25);
		cardPane.setBounds(position_x, position_y + 25, 80, 30);
		cardPane.setOpaque(false);
		visiblePane.setOpaque(false);
		hidePane.setOpaque(false);
		
		frame.getContentPane().setBackground(Color.RED);
		
		
		
		menubut.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				if(visible){
					cardLayout.show(cardPane, "p2");
					visible = false;
				}else{
					cardLayout.show(cardPane, "p1");
					visible = true;
				}
				
			}
		});
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new ButtonMenutest();
	}

}
